#include "bq.hpp"
#include<unistd.h>
#define NUM 10

void* consumer(void* c)
{
	BlockQueue<int>* bq = (BlockQueue<int>*)c;

	int out = 0;
	while(1)
	{
		bq->Get(&out);
		std::cout<<"Consumer get data: "<< out << std::endl;
	}
	return nullptr;
}
void* productor(void* p)
{
	BlockQueue<int>* bq = (BlockQueue<int>*)p;

	int in = 1;
	while(1)
	{
		sleep(1);
		bq->Put(in);
		std::cout << "Productor put data: " << in << std::endl;
		in++;
		in %= 100;
	}
	return nullptr;
}

int main()
{
	BlockQueue<int>* bq = new BlockQueue<int>(NUM);
	pthread_t c,p;
	pthread_create(&c,nullptr,consumer,bq);
	pthread_create(&p,nullptr,productor,bq);

	pthread_join(c,nullptr);
	pthread_join(p,nullptr);

	delete bq;
	return 0;
}
